/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: jse2303 - Dir5
 * <p>Powered by webrx On 2023-07-21 09:44:33
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Dir5 {
    static Map<String, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        //统计某目录下 文件类型的个数 D:\takeaway
        count(new File("D:\\takeaway"));
        System.out.println("-----------------");
        for (String key : map.keySet()) {
            System.out.printf("%s = %d%n", key, map.get(key));
        }
    }

    public static void count(File src) {
        for (File f : src.listFiles()) {
            if (f.isDirectory()) {
                count(f);
            } else {
                String fn = f.getName();
                //if (fn.endsWith(".java")) {
                int pos = fn.lastIndexOf(".");
                String ext = pos != -1 ? fn.substring(pos + 1) : "unknow";
                if (map.containsKey(ext)) {
                    map.put(ext, map.get(ext) + 1);
                } else {
                    map.put(ext, 1);
                }
                //}
            }
        }
    }
}
